<template>
	<view style="width: 100%;display: flex;flex-direction: column;">
		<u-navbar back-text="" title="">
			<view style="width: 100%;display: flex;justify-content: center;font-weight: bold;font-size: 34rpx;margin-left: 15rpx;">
				移除群成员
			</view>
			<view slot="right">
				<view @click="removeconfirm" v-if="checklist.length > 0" style="margin-right: 30rpx;width: 120rpx;height: 56rpx;display: flex;align-items: center;justify-content: center;background: #ff2c02;border-radius: 8rpx;color: white;">
					删除({{checklist.length}})
				</view>
				<view v-else style="margin-right: 30rpx;width: 120rpx;height: 56rpx;display: flex;align-items: center;justify-content: center;background: #ff2c0255;border-radius: 8rpx;color: white;">
					删除
				</view>
			</view>
		</u-navbar>
		<view @click="checkuser(item)" v-for="(item,k) in users" style="width: 100%;display: flex;align-items: center;justify-content: space-between;height: 100rpx;border-bottom: 1rpx solid #f1f1f1;background: #fff;">
			<view style="margin-left: 20rpx;display: flex;align-items: center;">
				<u-avatar :src="$store.state.common.systemInfo.fileurl + 'avatar/' + item.uid + '.jpg'" size="70" mode="square"></u-avatar>
				<view style="margin-left: 10rpx;">
					{{item.name}}
				</view>
			</view>
			<view class="">
				<image v-if="checklist.includes(item.uid)" src="/static/images/checked.png" style="width: 46rpx;height: 46rpx;margin-right: 25rpx;" mode=""></image>
				<image v-else src="/static/images/check.png" style="width: 46rpx;height: 46rpx;margin-right: 25rpx;" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				id: '',
				user:{},
				checklist:[]
			}
		},
		onLoad({
			id
		}) {
			this.id = id
			this.user = this.$store.state.user.user
		},
		computed: {
			...mapState({
				info: function(state) {
					const ret = state.friend.list.find(e => e.gid == this.id)
					return ret
				},
				users: function(state) {
					const ret = state.friend.list.find(e => e.gid == this.id)
					return ret.users?.filter(e=>e.uid != state.user.user.id)
				},
				myself: function(state) {
					const ret = state.friend.list.find(e => e.gid == this.id)
					const myself = ret.users.find(e=>e.uid == state.user.user.id)
					return myself
				},
				group: function(state) {
					const ret = state.friend.chatgroup.find(e => e.id == this.id)
					return ret
				}
			})
		},
		methods:{
			checkuser:function(item){
				if(this.checklist.includes(item.uid)){
					this.checklist = this.checklist.filter(e=>e != item.uid)
				}else{
					this.checklist.push(item.uid)
				}
			},
			removeconfirm:async function(){
				const id = this.id
				const ret = await this.$u.put(`friend/friend/removeguser/${id}`,{
					list:this.checklist
				})
				if(ret && ret.success){
					uni.showToast({
						title:"移除成功"
					})
				}
				setTimeout(()=>{
					uni.navigateBack(-2)
				},800)
			},
		}
	}
</script>

<style scoped>
	page{
		background: white;
	}
</style>